package com.shuangyu.service.Impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shuangyu.entity.AddressBook;
import com.shuangyu.mapper.AddressBookMapper;
import com.shuangyu.service.AddressBookService;
import org.springframework.stereotype.Service;

@Service
public class AddressBookServiceImpl extends ServiceImpl<AddressBookMapper, AddressBook> implements AddressBookService {
    @Override
    public void updateByDefault(AddressBook addressBook) {
        LambdaUpdateWrapper<AddressBook> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.set(AddressBook::getIsDefault, 0).eq(AddressBook::getUserId, addressBook.getUserId());
        this.update(updateWrapper);

        updateWrapper.clear();

        updateWrapper.set(AddressBook::getIsDefault, 1).eq(AddressBook::getId, addressBook.getId());
        this.update(updateWrapper);

    }
}
